package com.interview02;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 * Copyright (C), 2018-2020
 * FileName: Demo5
 * Author:   kongfanyu
 * Date:     2020/12/16 11:33
 * 程序运行过程中，动态的调用类的属性和方法，Spring，Mybatis都用到反射
 */
public class Demo5 {

    public static void main(String[] args) throws Exception {
        Class<?> clazz = Class.forName("com.interview02.Student");
        Object o = clazz.newInstance();
        Field[] declaredFields = clazz.getDeclaredFields();
        for (Field field: declaredFields){
            System.out.println(field.getName());
        }

        Method sayHello = clazz.getDeclaredMethod("sayHello", null);
        sayHello.invoke(o,null);

    }

}
